<?php
namespace App\Http\Controllers\Api\v1\Horoscope;

use App\Http\Controllers\Api\BaseController;
use Illuminate\Http\Request;
use DB;

class SettingController extends BaseController
{

   public function __construct()
    {
        parent::filter_xss();
      if(!defined('IS_ACCESS_TOKEN_CHECKED'))
        {
            parent::check_func('check');
            parent::__construct();// 接口调用验证
        }
    }

    /**
     * 八字设置更新
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function put(Request $Request)
    {
        $uid = $request->uid;
        if(!$uid)
        {
            return response()->json(['code'=>10040,'msg'=>'用户不存在！']);
        }

        $type = intval($Request->input('type'));

        $start = intval($Request->input('start'));

        $isset = DB::table('horoscope_setting')->where(['uid'=>$uid])->first();
        if(!empty($isset))
        {
            if(DB::table('horoscope_setting')
                ->where(['uid'=>$uid])->update(['type'=>$type,'start'=>$start]))
            {
                return response()->json(['code'=>200,'msg'=>'切换成功！']);
            }
        }
        else
        {
            if(DB::table('horoscope_setting')
                ->insertGetId(['uid'=>$uid,'type'=>$type,'start'=>$start]))
            {
                return response()->json(['code'=>200,'msg'=>'切换成功！']);
            }
        }

        return response()->json(['code'=>10400,'msg'=>'切换失败！']);
    }

}
